<template>
  <view>
    <view class="h-con h-flex">
      <view class="flex-1">
        <qs-tab-swiper
          :tabs="tabs"
          :config="{
            apiName: 'data/list/shop_goods',
            type: 'goods',
          }"
          :filterParams="goodsParams"
        />
        <!-- <q-loading v-if="loading" /> -->
        <!-- <index-goods /> -->
      </view>
    </view>
    <q-cart-anim in-tab />
  </view>
</template>

<script>
import { mapState } from "vuex";

const shareInfo = {
  title: "认养一颗榴莲树",
  path: "/pages/index/index",
};

export default {
  components: {},
  onShareAppMessage() {
    return shareInfo;
  },
  onShareTimeline() {
    return shareInfo;
  },
  data() {
    return {
      loading: false,
      goodsParams: {
        shop_id: this.shopId,
        type: ">0",
        _order: "seq desc",
        _select: "id,type,name,price,cover",
      },
    };
  },
  computed: {
    ...mapState(["myLocation", "userInfo", "typeList", "shopId"]),
    tabs() {
      return [
        {
          name: "推荐",
        },
        ...this.typeList.map((it) => {
          return {
            name: it.name,
            params: {
              type: it.id,
            },
          };
        }),
      ];
    },
  },
  onLoad() {
    this.getTypeList();
  },
  methods: {
    onPos() {
      this.$toast("dev");
    },
    async getTypeList() {
      try {
        const { data } = await uni.$api.get("/data/list/shop_goods_type", {
          params: {
            shop_id: this.shopId,
            _order: "seq desc",
          },
        });
        this.$setStore({
          typeList: data,
        });
        // this.$store.dispatch("getMyLocation");
      } catch (error) {
        console.log(error);
      }
    },
  },
};
</script>
